/*
 * @Description: 数组
 * @Author: rendc
 * @Date: 2025-10-23 11:14:04
 * @LastEditors: rendc
 * @LastEditTime: 2025-10-23 15:03:36
 */
var arr = new Array();
var arr = [];
console.log('🤡 CC - arr:', arr);
// 创建一个长度为3的数组 undefined占位
var arr = new Array(3);
var arr = [undefined, undefined, undefined];
console.log('🤡 CC - arr:', arr);
var arr = new Array(3, 4);
console.log('🤡 CC - arr:', arr);
var arr = [3, 4]
console.log('🤡 CC - arr:', arr);
var arr = [[0, 0], [3, 4]]
console.log('🤡 CC - arr:', arr);
// arr[1][1]
console.log('🤡 CC - arr[1][1]:', arr[1][1]);
console.log('🤡 CC - arr[0]:', arr[0]);
var arr = new Array("3");
console.log('🤡 CC - arr:', arr);
var arr = new Array("3", "4");
console.log('🤡 CC - arr:', arr);


var arr = [1, 2, 3, null, "5", true, {}, [], function () { },];
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - arr.length:', arr.length);
// 数组长度是9 数组的下标0-8
console.log('🤡 CC - arr[8]:', arr[8]);
console.log('🤡 CC - arr[9]:', arr[9]);
console.log('🤡 CC - arr.length:', arr.length);
arr[10] = 10;
console.log('🤡 CC - arr[10]:', arr[10]);
console.log('🤡 CC - arr[9]:', arr[9]); // undefined
console.log('🤡 CC - arr.length:', arr.length);// 11
console.log('🤡 CC - arr[11]:', arr[11]); // undefined
console.log('🤡 CC - arr.length:', arr.length);// 11
console.log('🤡 CC - arr:', arr);
arr.length = 5;
console.log('🤡 CC - arr:', arr);
// 普通for循环
for (let i = 0; i < arr.length; i++) {
  const element = arr[i];
  console.log('🤡 CC - for - element:', element);
}
// for in 
for (var i in arr) {
  var element = arr[i];
  console.log('🤡 CC - forin - element:', element);
}
// 增强for循环 forEach
arr.forEach(element => {
  console.log('🤡 CC - forEach - element:', element);
});
// while do-while
var arrStr = arr.toString();
console.log('🤡 CC - arrStr:', arrStr);
var arrStr = arr.join("");
console.log('🤡 CC - arrStr:', arrStr);
// arrStr[0]
console.log('🤡 CC - arrStr[0]:', arrStr[0]);
console.log('🤡 CC - arrStr[1]:', arrStr[1]);
console.log('🤡 CC - arrStr[2]:', arrStr[2]);

var arrJSON = JSON.stringify(arr);
var newArr = JSON.parse(arrJSON);
console.log('🤡 CC - newArr[0]:', newArr[0]);
console.log('🤡 CC - newArr[1]:', newArr[1]);


console.log('🤡 CC - typeof  arrJSON:', typeof arrJSON);
console.log('🤡 CC - typeof arr:', typeof arr);

var flag = Array.isArray(arr);
console.log('🤡 CC - flag:', flag);

var str = "string";
console.log('🤡 CC - str:', str);
str[0]
console.log('🤡 CC - str[0]:', str[0]);
console.log('🤡 CC - str[1]:', str[1]);

var arr = Array.from(str);
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - str:', str);

var arr = Array.of(1, 2, 3);
var arr = Array.of(3);
// var arr = new Array(1, 2, 3);
// var arr = new Array(3);
console.log('🤡 CC - arr:', arr);
var a = arr.push(4, 5);
// 数组扩容
console.log('🤡 CC - a:', a);
console.log('🤡 CC - arr:', arr);


var result = arr.pop();
console.log('🤡 CC - result:', result);
console.log('🤡 CC - arr:', arr);

var result = arr.shift();
console.log('🤡 CC - result:', result);
console.log('🤡 CC - arr:', arr);

var result = arr.unshift(0, 1, 2, 3);
console.log('🤡 CC - result:', result);
console.log('🤡 CC - arr:', arr);

// 数组是有序的还是无序的，是否按照插入顺序存储元素（不是排序）
arr.push(1);
arr.push(3);
arr.push(10);
arr.push(5);
arr.push(7);
console.log('🤡 CC - arr:', arr);
var result = arr.reverse();
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - result:', result);
// hello,world

// var arr = [1, 0, 3, 2, 5, 4, 7, 6, 10, 15, 18, 20];
var arr = ["B", "C", "A"];
console.log('🤡 CC - arr:', arr);
var result = arr.sort();
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - result:', result);



